﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jayden.Dll.Web.Controls;
using Jayden.Dll.Sc2.Descriptions;

namespace Jayden.Site.Sc2.Dll
{
	public class EntityTable : DataTable<EntityDescription>
	{

		private List<Column> m_EntityColumns = new List<Column>(new Column[]
		{
			new Column(null, null, delegate(EntityDescription value, Column column, int index) { return ParseHtml("<img src=\"/Images/" + value.IconId + ".gif\" alt=\"" + value.Id + "\" />"); }, null, false, true),
			new Column("Name", 300, delegate(EntityDescription value, Column column, int index) { return ParseHtml("<a href=\"?entityId=" + value.Id + "\">" + value.Name + "</a>"); }, null, false, true),
			new Column("Mineral", null, delegate(EntityDescription value, Column column, int index) { return ParseText(value.Mineral.ToString()); }, null),
			new Column("Vespene", null, delegate(EntityDescription value, Column column, int index) { return ParseText(value.Vespene.ToString()); }, null),
			new Column("Time", null, delegate(EntityDescription value, Column column, int index) { return ParseText(value.Time.ToString()); }, null),
			new Column("Food", null, delegate(EntityDescription value, Column column, int index) { return ParseText(value.Supply.ToString()); }, null),
			new Column("Count", null, delegate(EntityDescription value, Column column, int index) { return ParseText(value.Count.ToString()); }, null),
			new Column("LifeTime", null, delegate(EntityDescription value, Column column, int index) { return ParseText(value.LifeTime.ToString()); }, null),
			new Column("HaveEnergy", null, delegate(EntityDescription value, Column column, int index) { return ParseText(value.HaveEnergy.ToString()); }, null),
			new Column("Level", null, delegate(EntityDescription value, Column column, int index) { return ParseText(value.Level.ToString()); }, null)
		});

		public override void Load(System.Xml.XmlNode node, Jayden.Dll.Web.HtmlControlLoader loader)
		{
			base.Load(node, loader);

			foreach (Column c in m_EntityColumns)
				AddColumn(c);
		}

		public void Set(IEnumerable<EntityDescription> list)
		{
			foreach (EntityDescription e in list)
			{
				AddTr(e).Title = e.Name;
			}
		}

	}
}
